package exam.axhu.junit;

import static org.junit.Assert.*;

import java.util.List;

import exam.axhu.entity.ShortAnswer;
import exam.axhu.service.ShortAnswerService;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ShortAnswerTest {
	private static ShortAnswerService shortAnswerService;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception{
		try {
			ApplicationContext act = new ClassPathXmlApplicationContext("beans.xml");
			shortAnswerService =(ShortAnswerService) act.getBean("shortAnswerServiceImpl");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	@Test
	public void save() {
		if(shortAnswerService.save(new ShortAnswer("姓胡的名人","胡适，胡锦涛，胡雪岩"))==1)
			System.out.println("already have!");
	
	}
	
	@Test
	public void delete() {
		shortAnswerService.delete(1);
	
	}
	
	@Test
	public void update() {
		ShortAnswer shortAnswer = shortAnswerService.findByID(1);
		shortAnswer.setShortAnswerAnswer("周恩来，周星驰，周润发，周佛海");
		shortAnswerService.update(shortAnswer);
	
	}
	
	
	
	@Test
	public void find() {
		ShortAnswer ems = shortAnswerService.findByID(2);
		/*if(ems==null) System.out.println("NO");
		else*/
			System.out.println(ems.getShortAnswerID());
	}
	
	
	@Test
	public void list() {
	
		List<ShortAnswer> ems = shortAnswerService.list();
		for(ShortAnswer em:ems){
			System.out.println(em.getShortAnswerID());
		}
				
	}

}
